package com.suanfa.node;

import java.util.Stack;

public class RepeatNode {

    public static void main(String[] args) {
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(1);
        ListNode node3 = new ListNode(1);
        ListNode node4 = new ListNode(2);
        ListNode node5 = new ListNode(3);
        ListNode node6 = new ListNode(4);
        ListNode node7 = new ListNode(5);
        node1.next=node2;
        node2.next=node3;
        node3.next=node4;
        node4.next=node5;
        node5.next=node6;
        node6.next=node7;
        ListNode list = getNoRepeatNode(node1);
        while(list != null){
            System.out.print(list.value+",");
            list=list.next;
        }
    }


    public static ListNode getNoRepeatNode(ListNode head){

        ListNode newHead = new ListNode(0);
        newHead.next = head;
        ListNode current = newHead;
        while(current.next != null && current.next.next != null){

            if(current.next.value == current.next.next.value) {
                int value = current.next.value;
                while (current.next != null && current.next.value == value) {
                    current.next = current.next.next;
                }
            }else {
                current = current.next;
            }

        }


    return newHead.next;
    }
}

